/**
 * Created by oneminute on 7/17/14.
 */

var lz = require("../lib/utils/modules")();

exports.get = function (_req, _res, _opts, _callback) {
    var user = _req.user;
    var gid = _req.query.gid;
    if (!user) {
        lz.Logger.warn("/owngoodsdetails: 用户不存在。");
        _callback(lz.Config.errors.getError(lz.Config.errors.REQUEST_TEMPUSER_ERROR));
        return;
    }
    if (!gid) {
        lz.Logger.warn("/owngoodsdetails: 用户请求的商品id不存在。");
        _callback(lz.Config.errors.getError(lz.Config.errors.REQUEST_MISS_VALUE, {name: "gid"}));
        return;
    }
    var commodity = new lz.Commodity({id: gid});
    commodity.load({method: "byId"}, function (_err, _commodity) {
        if (_commodity && _commodity.uid == user.id) {
            var info = _commodity.getInfo('f');
            _callback(null, user, info);
        } else {
            lz.Logger.warn("/owngoodsdetails: 请求的商品不属于该用户。");
            _callback(lz.Config.errors.getError(lz.Config.errors.REQUEST_DATA_NOT_BELANG_USER));
        }
    });
};